<!DOCTYPE html>
<html lang="zh-CN">





<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.png">
  <link rel="icon" type="image/png" href="/img/favicon.png">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="熊儿老猫的博客">
  <meta name="author" content="Zhenglin Li">
  <meta name="keywords" content="">
  <title>微信小程序黑马优购（一） - 熊儿老猫的博客</title>

  <link  rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.staticfile.org/github-markdown-css/4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    <link  rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/10.0.0/styles/github-gist.min.css" />
  

  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_yg9cfy8wd6.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_pjno9b9zyxs.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script  src="/js/utils.js" ></script>
<meta name="generator" content="Hexo 4.2.1"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/">&nbsp;<strong>熊儿老猫的Blog</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/links/">
                <i class="iconfont icon-link-fill"></i>
                友链
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" data-toggle="modal" data-target="#modalSearch">&nbsp;&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="view intro-2" id="background" parallax=true
         style="background: url('https://farm1.staticflickr.com/700/21371649841_2d54662091_z.jpg') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="container text-center white-text fadeInUp">
            <span class="h2" id="subtitle">
              
            </span>

            
              
  <div class="mt-3 post-meta">
    <i class="iconfont icon-date-fill" aria-hidden="true"></i>
    <time datetime="2020-06-25 19:53">
      2020年6月25日 晚上
    </time>
  </div>


<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      890 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      13
       分钟
    </span>
  

  
  
    
      <!-- 不蒜子统计文章PV -->
      <span id="busuanzi_container_page_pv" style="display: none">
        <i class="iconfont icon-eye" aria-hidden="true"></i>
        <span id="busuanzi_value_page_pv"></span> 次
      </span>
    
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid">
  <div class="row">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-md">
      <div class="container nopadding-md" id="board-ctn">
        <div class="py-5" id="board">
          <div class="post-content mx-auto" id="post">
            
              <p class="note note-info">
                
                  本文最后更新于：12 天前
                
              </p>
            
            <article class="markdown-body">
              <p>本篇博客将实时更新我学习使用微信小程序搭建范例黑马优购的过程。</p>
<p>教程地址：<a href="https://www.bilibili.com/video/BV1nE41117BQ?p=47" target="_blank" rel="noopener">https://www.bilibili.com/video/BV1nE41117BQ?p=47</a></p>
<p>参考文档：<a href="https://www.showdoc.cc/128719739414963" target="_blank" rel="noopener">https://www.showdoc.cc/128719739414963</a></p>
<h2 id="一、-新建小程序项目"><a href="#一、-新建小程序项目" class="headerlink" title="一、 新建小程序项目"></a>一、 新建小程序项目</h2><p>打开微信开发者工具，新建小程序项目，然后执行如下操作：</p>
<ol>
<li><p>app.json中删除”pages/logs/logs”</p>
</li>
<li><p>app.json中的window字段改动如下：<code>&quot;navigationBarTitleText&quot;: &quot;黑马优购&quot;</code></p>
</li>
<li><p>pages中logs’文件夹删除</p>
</li>
<li><p>app.wxss中删除全部内容</p>
</li>
<li><p>app.js中删除全部代码，并在vscode中输入wx-app，即可自动补全所需必要代码，再删除globleData</p>
</li>
<li><p>pages中index.wxml, index.wxss删除全部语句, index.js中保留必要语句，同上在vscode中输入wx-page</p>
</li>
<li><p>pages/index/index.json中，新增如下：<code>&quot;navigationBarTitleText&quot;: &quot;优购首页&quot;</code></p>
</li>
<li><p>unils文件夹删除</p>
<p>至此，目录结构已无冗余，接下来我们新增项目必要的文件夹和文件</p>
</li>
</ol>
<p>##　二、 搭建目录结构</p>
<p>把目录结构改为如下图所示：</p>
<p><img src= "/img/loading.gif" data-src="https://i.loli.net/2020/06/28/49GKD6VP7lmRfEo.png" srcset="/img/loading.gif" alt="image-20200625205252095"></p>
<p>各个目录的作用如下：</p>
<ol>
<li>style： 存放公共样式</li>
<li>components： 存放组件</li>
<li>lib： 存放第三方库</li>
<li>untils： 自己的帮助库</li>
<li>request： 自己的借口帮助库</li>
</ol>
<h2 id="三、-搭建项目的页面"><a href="#三、-搭建项目的页面" class="headerlink" title="三、 搭建项目的页面"></a>三、 搭建项目的页面</h2><p><img src= "/img/loading.gif" data-src="https://i.loli.net/2020/06/28/SZEYAydNDWfLqnK.png" srcset="/img/loading.gif" alt="image-20200625210001721"></p>
<p>在app.json中，修改pages字段，如下</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">&quot;pages&quot;: [ &quot;pages&#x2F;index&#x2F;index&quot;,</span><br><span class="line"></span><br><span class="line"> &quot;pages&#x2F;category&#x2F;index&quot;,</span><br><span class="line"></span><br><span class="line"> &quot;pages&#x2F;goods_list&#x2F;index &quot;,</span><br><span class="line"></span><br><span class="line"> &quot;pages&#x2F;goods_detail&#x2F;index &quot;,</span><br><span class="line"></span><br><span class="line"> &quot;pages&#x2F;cart&#x2F;index&quot;,</span><br><span class="line"></span><br><span class="line"> &quot;pages&#x2F;collect&#x2F;index&quot;,</span><br><span class="line"></span><br><span class="line"> &quot;pages&#x2F;order&#x2F;index&quot;,</span><br><span class="line"></span><br><span class="line"> &quot;pages&#x2F;search&#x2F;index&quot;,</span><br><span class="line"></span><br><span class="line"> &quot;pages&#x2F;user&#x2F;index&quot;,</span><br><span class="line"></span><br><span class="line"> &quot;pages&#x2F;feedback&#x2F;index&quot;,</span><br><span class="line"></span><br><span class="line"> &quot;pages&#x2F;login&#x2F;index&quot;,</span><br><span class="line"></span><br><span class="line"> &quot;pages&#x2F;auth&#x2F;index&quot;,</span><br><span class="line"></span><br><span class="line"> &quot;pages&#x2F;pay&#x2F;index&quot;</span><br><span class="line"></span><br><span class="line"> ],</span><br></pre></td></tr></table></figure>

<h2 id="四、-引入字体图标"><a href="#四、-引入字体图标" class="headerlink" title="四、 引入字体图标"></a>四、 引入字体图标</h2><ol>
<li><p>打开阿里巴巴字体图标库，地址<a href="https://www.iconfont.cn/，选择图标后加入购物车。![image-20200625212648119](https://i.loli.net/2020/06/28/WEayt6IYfjlrzQD.png)" target="_blank" rel="noopener">https://www.iconfont.cn/，选择图标后加入购物车。![image-20200625212648119](https://i.loli.net/2020/06/28/WEayt6IYfjlrzQD.png)</a></p>
</li>
<li><p>复制下图中链接在浏览器中打开，页面打开后复制页面内所有的内容。</p>
</li>
<li><p>在style中新建iconfont.wxss,粘贴刚才复制的全部内容。</p>
</li>
<li><p>在app.wxss中导入字体图标，app.wxss加入如下代码<code>@import &quot;./styles/iconfont.wxss&quot;;</code></p>
</li>
<li><p>用法测试：在pages/index/index.wxml中输入如下代码</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&lt;view&gt;首页	</span><br><span class="line">	&lt;text class&#x3D;&quot;iconfont incon-shoucang1&quot;&gt;&lt;&#x2F;text&gt;</span><br><span class="line">&lt;&#x2F;view&gt;</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">## 五、 搭建项目tabber结构</span><br><span class="line"></span><br><span class="line">1. 在app.json的window字段同层级下新增如下代码：</span><br><span class="line"></span><br><span class="line">   &#96;&#96;&#96; </span><br><span class="line">   &quot;tabBar&quot;: &#123;</span><br><span class="line">       &quot;color&quot;: &quot;#999&quot;,</span><br><span class="line">       &quot;selectedColor&quot;: &quot;#ff2d4a&quot;,</span><br><span class="line">       &quot;backgroundColor&quot;: &quot;#fafafa&quot;,</span><br><span class="line">       &quot;position&quot;: &quot;bottom&quot;,</span><br><span class="line">       &quot;borderStyle&quot;: &quot;black&quot;,</span><br><span class="line">       &quot;list&quot;: [</span><br><span class="line">         &#123;</span><br><span class="line">           &quot;pagePath&quot;: &quot;pages&#x2F;index&#x2F;index&quot;,</span><br><span class="line">           &quot;text&quot;: &quot;首页&quot;,</span><br><span class="line">           &quot;iconPath&quot;: &quot;icons&#x2F;home.png&quot;,</span><br><span class="line">           &quot;selectedIconPath&quot;: &quot;icons&#x2F;home1.png&quot;</span><br><span class="line">         &#125;,</span><br><span class="line">         &#123;</span><br><span class="line">           &quot;pagePath&quot;: &quot;pages&#x2F;category&#x2F;index&quot;,</span><br><span class="line">           &quot;text&quot;: &quot;分类&quot;,</span><br><span class="line">           &quot;iconPath&quot;: &quot;icons&#x2F;cart.png&quot;,</span><br><span class="line">           &quot;selectedIconPath&quot;: &quot;icons&#x2F;cart1.png&quot;</span><br><span class="line">         &#125;,</span><br><span class="line">         &#123;</span><br><span class="line">           &quot;pagePath&quot;: &quot;pages&#x2F;cart&#x2F;index&quot;,</span><br><span class="line">           &quot;text&quot;: &quot;购物车&quot;,</span><br><span class="line">           &quot;iconPath&quot;: &quot;icons&#x2F;category.png&quot;,</span><br><span class="line">           &quot;selectedIconPath&quot;: &quot;icons&#x2F;category1.png&quot;</span><br><span class="line">         &#125;,</span><br><span class="line">         &#123;</span><br><span class="line">           &quot;pagePath&quot;: &quot;pages&#x2F;user&#x2F;index&quot;,</span><br><span class="line">           &quot;text&quot;: &quot;我的&quot;,</span><br><span class="line">           &quot;iconPath&quot;: &quot;icons&#x2F;me.png&quot;,</span><br><span class="line">           &quot;selectedIconPath&quot;: &quot;icons&#x2F;me1.png&quot;</span><br><span class="line">         &#125;</span><br><span class="line">       ]</span><br><span class="line">     &#125;,</span><br></pre></td></tr></table></figure>
</li>
<li><p>各字段说明详见开发者文档。</p>
</li>
</ol>
<h2 id="六、初始化页面样式"><a href="#六、初始化页面样式" class="headerlink" title="六、初始化页面样式"></a>六、初始化页面样式</h2><ol>
<li><p>在app.wxss中加入如下代码</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">page,view,text,swiper,swiper-item,image,navigator&#123;</span><br><span class="line">  padding: 0;</span><br><span class="line">  margin: 0;</span><br><span class="line">  box-sizing: border-box;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">&#x2F;* </span><br><span class="line">  主题颜色 </span><br><span class="line">  支持变量</span><br><span class="line">*&#x2F;</span><br><span class="line">page&#123;</span><br><span class="line">  --themeColor:#eb4450;</span><br><span class="line">  font-size: 28rpx;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>使用主题颜色</p>
<p>在index.wxss中加入如下代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;* pages&#x2F;index&#x2F;index.wxss *&#x2F;</span><br><span class="line">view&#123;</span><br><span class="line"></span><br><span class="line">  &#x2F;* 使用主题颜色 *&#x2F;</span><br><span class="line"></span><br><span class="line">  color:var(--themeColor);</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

</li>
</ol>

            </article>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F/">微信小程序</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/%E9%BB%91%E9%A9%AC%E4%BC%98%E8%B4%AD/">黑马优购</a>
                    
                  </div>
                
              </div>
              
              
                <div class="post-prevnext row">
                  <div class="post-prev col-6">
                    
                    
                      <a href="/2020/06/28/%E6%B5%85%E6%9E%90%E5%8A%A8%E7%89%A9%E5%86%9C%E5%9C%BA/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">浅析动物农场</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </div>
                  <div class="post-next col-6">
                    
                    
                      <a href="/2020/06/16/my-first-blog/">
                        <span class="hidden-mobile">my-first-blog</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </div>
                </div>
              
            </div>

            
          </div>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div id="tocbot"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    
  </main>

  
    <a id="scroll-top-button" href="#" role="button">
      <i class="iconfont icon-arrowup" aria-hidden="true"></i>
    </a>
  

  
    <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
  

  

  

  <footer class="mt-5">
  <div class="text-center py-3">
    <div>
      <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a>
      <i class="iconfont icon-love"></i>
      <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener">
        <span>Fluid</span></a>
    </div>
    

    

    
  </div>
</footer>

<!-- SCRIPTS -->
<script  src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js" ></script>
<script  src="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/js/bootstrap.min.js" ></script>
<script  src="/js/debouncer.js" ></script>
<script  src="/js/main.js" ></script>

<!-- Plugins -->


  
    <script  src="/js/lazyload.js" ></script>
  



  <script defer src="https://cdn.staticfile.org/clipboard.js/2.0.6/clipboard.min.js" ></script>
  <script  src="/js/clipboard-use.js" ></script>



  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





  <script  src="https://cdn.staticfile.org/tocbot/4.11.1/tocbot.min.js" ></script>
  <script>
    $(document).ready(function () {
      var boardCtn = $('#board-ctn');
      var boardTop = boardCtn.offset().top;

      tocbot.init({
        tocSelector: '#tocbot',
        contentSelector: 'article.markdown-body',
        headingSelector: 'h1,h2,h3,h4,h5,h6',
        linkClass: 'tocbot-link',
        activeLinkClass: 'tocbot-active-link',
        listClass: 'tocbot-list',
        isCollapsedClass: 'tocbot-is-collapsed',
        collapsibleClass: 'tocbot-is-collapsible',
        collapseDepth: 0,
        scrollSmooth: true,
        headingsOffset: -boardTop
      });
      if ($('.toc-list-item').length > 0) {
        $('#toc').css('visibility', 'visible');
      }
    });
  </script>



  <script  src="https://cdn.staticfile.org/typed.js/2.0.11/typed.min.js" ></script>
  <script>
    var typed = new Typed('#subtitle', {
      strings: [
        '  ',
        "微信小程序黑马优购（一）&nbsp;",
      ],
      cursorChar: "_",
      typeSpeed: 88,
      loop: false,
    });
    typed.stop();
    $(document).ready(function () {
      $(".typed-cursor").addClass("h2");
      typed.start();
    });
  </script>



  <script  src="https://cdn.staticfile.org/anchor-js/4.2.2/anchor.min.js" ></script>
  <script>
    anchors.options = {
      placement: "right",
      visible: "hover",
      
    };
    var el = "h1,h2,h3,h4,h5,h6".split(",");
    var res = [];
    for (item of el) {
      res.push(".markdown-body > " + item)
    }
    anchors.add(res.join(", "))
  </script>



  <script  src="/js/local-search.js" ></script>
  <script>
    var path = "/local-search.xml";
    var inputArea = document.querySelector("#local-search-input");
    inputArea.onclick = function () {
      searchFunc(path, 'local-search-input', 'local-search-result');
      this.onclick = null
    }
  </script>



  <script  src="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.css" />

  <script>
    $('#post img:not(.no-zoom img, img[no-zoom]), img[zoom]').each(
      function () {
        var element = document.createElement('a');
        $(element).attr('data-fancybox', 'images');
        $(element).attr('href', $(this).attr('src'));
        $(this).wrap(element);
      }
    );
  </script>







  
  
    <script type="text/javascript">
      //定义获取词语下标
      var a_idx = 0;
      jQuery(document).ready(function ($) {
        //点击body时触发事件
        $("body").click(function (e) {
          //需要显示的词语
          var a = new Array("富强", "民主", "文明", "和谐", "自由", "平等", "公正", "法治", "爱国", "敬业", "诚信", "友善");
          //设置词语给span标签
          var $i = $("<span/>").text(a[a_idx]);
          //下标等于原来下标+1  余 词语总数
          a_idx = (a_idx + 1) % a.length;
          //获取鼠标指针的位置，分别相对于文档的左和右边缘。
          //获取x和y的指针坐标
          var x = e.pageX, y = e.pageY;
          //在鼠标的指针的位置给$i定义的span标签添加css样式
          $i.css({
            "z-index": 999,
            "top": y - 20,
            "left": x,
            "position": "absolute",
            "font-weight": "bold",
            "color": rand_color()
          });
          // 随机颜色
          function rand_color() {
            return "rgb(" + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + ")"
          }
          //在body添加这个标签
          $("body").append($i);
          //animate() 方法执行 CSS 属性集的自定义动画。
          //该方法通过CSS样式将元素从一个状态改变为另一个状态。CSS属性值是逐渐改变的，这样就可以创建动画效果。
          //详情请看http://www.w3school.com.cn/jquery/effect_animate.asp
          $i.animate({
            //将原来的位置向上移动180
            "top": y - 180,
            "opacity": 0
            //1500动画的速度
          }, 1500, function () {
            //时间到了自动删除
            $i.remove();
          });
        });
      })
      ;
    </script>
  














<script src="https://cdn.jsdelivr.net/npm/live2d-widget@^3.1.3/lib/L2Dwidget.min.js"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"scale":1,"hHeadPos":0.5,"vHeadPos":0.618,"jsonPath":"/live2dw/assets/tororo.model.json"},"display":{"superSample":2,"position":"right","width":150,"height":300,"hOffset":20,"vOffset":-90},"mobile":{"show":true,"scale":1},"react":{"opacityDefault":0.3,"opacityOnHover":0.3,"opacity":0.95},"log":false});</script></body>
</html>
